<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>	
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="pragma" content="no-cache"/>   
	<meta http-equiv="Cache-Control" content="no-cache, must-revadivdate"/>   
	<meta http-equiv="expires" content="0"/> 
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>后台管理系统</title>
	<link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin ">
  <div class="layui-header ">
    <div class="layui-logo">后台管理系统</div>	
    <!-- 头部区域（可配合layui已有的水平导航） -->
    <ul class="layui-nav layui-layout-left">
      <li class="layui-nav-item"><a href="">控制台</a></li>
      <li class="layui-nav-item"><a href="">商品管理</a></li>
      <li class="layui-nav-item"><a href="">用户</a></li>
      <li class="layui-nav-item">
        <a href="javascript:;">其它系统</a>
        <dl class="layui-nav-child">
          <dd><a href="">邮件管理</a></dd>
          <dd><a href="">消息管理</a></dd>
          <dd><a href="">授权管理</a></dd>
        </dl>
      </li>
    </ul>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item">
        <a href="javascript:;">
          <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
          贤心
        </a>
        <dl class="layui-nav-child">
          <dd><a href="">基本资料</a></dd>
          <dd><a href="">安全设置</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item"><a href="">退了</a></li>
    </ul>
  </div>
  
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree"  lay-filter="test">
        <li class="layui-nav-item layui-nav-itemed">
          <a class="" href="javascript:;">所有商品</a>
          <dl class="layui-nav-child">
            <dd><a href="javascript:;">列表一</a></dd>
            <dd><a href="javascript:;">列表二</a></dd>
            <dd><a href="javascript:;">列表三</a></dd>
            <dd><a href="">超链接</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">解决方案</a>
          <dl class="layui-nav-child">
            <dd><a href="javascript:;">列表一</a></dd>
            <dd><a href="javascript:;">列表二</a></dd>
            <dd><a href="">超链接</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item"><a href="">云市场</a></li>
        <li class="layui-nav-item"><a href="">发布商品</a></li>
      </ul>
    </div>
  </div>
  
  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">内容主体区域</div>
  </div>
  
  <div class="layui-footer">
    <!-- 底部固定区域 -->
    © layui.com - 底部固定区域
  </div>
</div>
<script language="JavaScript" src="../js/jquery.js"></script>
<script src="../layui/layui.js"></script>

<script language="javascript">

    function loadFunctions(){
        try{
            $.ajax({
                url: '../sys/function/tree',
                data:'',
                beforeSend: function(request) {
                    var accessToken = localStorage.getItem('accessToken');
                    request.setRequestHeader("Authentication",accessToken );
                },
                dataType: 'JSON',
                async: false,
                contentType:'application/json;charset=utf-8',
                type: 'GET',
                success: function(data, textStatus, response) {
                    console.log(JSON.stringify(data));
                    if (data.code == 200) {
                        $(".layui-layout-left").html('');
                        var html = "";
                        $.each(data.data,function(index,fun){
                            if(fun.children != null && fun.children.length > 0){
                                html += '<li class="layui-nav-item"><a href="javascript:;">'+fun.functionName+'</a><dl class="layui-nav-child">';
                                $.each(fun.children,function(i,child){
                                    html += '<dd><a href="'+child.href+'">'+child.functionName+'</a></dd>';
                                });
                                html += '</dl></li>';


                            }else{
                                html += '<li class="layui-nav-item"><a href="'+fun.href+'">'+fun.functionName+'</a></li>';
                            }
                        });
                        $(".layui-layout-left").html(html);
                        var element = layui.element;
                        element.render();
                    }else{
                        alert(data.message);
                    }
                },
                error: function () {
                    alert("error");
                }
            });

        }
        catch(e){
            console.log(e.message);
        }
    }

    loadFunctions();

    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;
        element.render();
    });

</script>

</body>
</html>